package com.example.dao;

import com.example.model.domain.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CommentMapper {
    // 分页展示某个文章的评论
    @Select("SELECT * FROM t_comment WHERE article_id=#{aid} ORDER BY id DESC")
    List<Comment> selectCommentWithPage(Integer aid);
    // 后台查询最新几条评论
    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    List<Comment> selectNewComment();
    // 站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM t_comment")
    Integer countComment();
    // 通过文章id删除评论信息
    @Delete("DELETE FROM t_comment WHERE article_id=#{aid}")
    void deleteCommentWithId(Integer aid);
    // 插入新的评论
    @Insert("INSERT INTO t_comment (article_id, user_id, content, created_at) VALUES (#{comment.articleId}, #{comment.userId}, #{comment.content}, #{comment.createdAt})")
    void pushComment(@Param("comment") Comment comment);
}